<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:a4j="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich">

<body>
	<ui:composition template="/template/template.xhtml">
		<ui:define name="body">
			<h:form onkeypress="if (event.keyCode == 13) return false;">

				<rich:notifyMessages stayTime="2000" nonblocking="true" />

				<a4j:poll id="poll" interval="10000" render="dataTable,lastRefreshDate" />
				<table>
					<tr>
						<td>
							<h:outputText value="#{msg.building_name}" styleClass="outputText" style="font-size: 16px;" />
						</td>
						
						<td>
							<h:selectOneMenu 
								id="search_building_name" styleClass="short_selectClass" 
								value="#{massRealTimeManageBean.selectedBuildingId}" valueChangeListener="#{massRealTimeManageBean.buildingValueChanged}" >
								<f:selectItems value="#{massRealTimeManageBean.buildingOptions}" />
								<a4j:ajax event="valueChange" render="search_floor_name,search_room_name" execute="@this" />

							</h:selectOneMenu>
						</td>
						
						<td>
							<h:outputText value="&#160;" />
							<h:outputText value="&#160;" />
							<h:outputText value="&#160;" />
						</td>
											
						<td>
							<h:outputText value="#{msg.floor_name}" styleClass="outputText" style="font-size: 16px;" />
						</td>
						
						<td>
							<h:selectOneMenu 
								id="search_floor_name" styleClass="short_selectClass" 
								value="#{massRealTimeManageBean.selectedFloorId}" valueChangeListener="#{massRealTimeManageBean.floorValueChanged}" >
								<f:selectItems value="#{massRealTimeManageBean.floorOptions}" />
								<a4j:ajax event="valueChange" render="search_room_name" execute="@this" />
							</h:selectOneMenu>
						</td>
						
						<td>
							<h:outputText value="&#160;" />	
							<h:outputText value="&#160;" />
							<h:outputText value="&#160;" />
						</td>
											
						<td>
							<h:outputText value="#{msg.room_name}" styleClass="outputText" style="font-size: 16px;" />
						</td>
						<td>
							<h:selectOneMenu 
								id="search_room_name" styleClass="short_selectClass" 
								value="#{massRealTimeManageBean.selectedRoomId}" valueChangeListener="#{massRealTimeManageBean.roomValueChanged}" >
								<f:selectItems value="#{massRealTimeManageBean.roomOptions}" />
								<a4j:ajax event="valueChange" render="send_btn" execute="@this" />
							</h:selectOneMenu>
						</td>
						
						<td>
							<h:outputText value="&#160;" />
							<h:outputText value="&#160;" />
							<h:outputText value="&#160;" />
						</td>
					
						<td>
							<a4j:commandButton 
								styleClass="buttonClass" style="font-size: 16px;" 
								value="#{msg.search_refresh}" action="#{massRealTimeManageBean.search}" 
								render="@form" />
						</td>
					</tr>
				</table>
				
				<h:panelGrid>
					<rich:panel width="1000px" header="#{msg.mass_real_time_status}" style="font-size: 16px;">
						<table>
							<tr>
								<td>#{msg.common_updatedate}: <h:outputText id="lastRefreshDate" value="#{massRealTimeManageBean.lastRefreshDate}" /></td>
							</tr>
							<tr>
								<td>
									<rich:extendedDataTable 
										id="dataTable" width="100%" rows="16" frozenColumns="2"
										value="#{massRealTimeManageBean.realTimeControls}" var="realTimeControl" iterationStatusVar="it">
										
										<f:facet name="noData">
								        	<h:outputText value="#{msg.no_record_found}" />
								        </f:facet>	
										 								
										<rich:column width="30px" style="text-align: center;">
											<f:facet name="header">
								                <h:outputText value="#{msg.index_logo}" />
								            </f:facet>						 
											<h:outputText value="#{it.index + 1}" />						
										</rich:column>
										
										<rich:column width="200px" style="text-align: center;">
											<f:facet name="header">
								                <h:outputText value="#{msg.machine_name}" />
								            </f:facet>						 
											<h:outputText value="#{realTimeControl.machine.machineName}" />						
										</rich:column>
										
										<rich:column width="80px" style="text-align: center;">
											<f:facet name="header">
								                <h:outputText value="#{msg.start_option}" />
								            </f:facet>						 
											<h:outputText value="#{msg.start_on}" rendered="#{realTimeControl.start}" />						
											<h:outputText value="#{msg.start_off}" rendered="#{!realTimeControl.start}" />
										</rich:column>
										
										<rich:column width="120px" style="text-align: center;">
											<f:facet name="header">
								                <h:outputText value="#{msg.room_temperature}(#{msg.celsius})" />
								            </f:facet>						 
											<h:outputText value="#{realTimeControl.roomTemperature}" />						
										</rich:column>
										
										<rich:column width="120px" style="text-align: center;">
											<f:facet name="header">
								                <h:outputText value="#{msg.temperature}(#{msg.celsius})" />
								            </f:facet>						 
											<h:outputText value="#{realTimeControl.temperature}" />						
										</rich:column>

										<rich:column width="120px" style="text-align: center;">
											<f:facet name="header">
								                <h:outputText value="#{msg.minimum_temperature}(#{msg.celsius})" />
								            </f:facet>						 
											<h:outputText value="#{realTimeControl.minimumTemperature}" />						
										</rich:column>							
										
										<rich:column width="95px" style="text-align: center;">
											<f:facet name="header">
								                <h:outputText value="#{msg.fan_speed}" />
								            </f:facet>						 
											<h:outputText value="#{msg.fan_speed_auto}" rendered="#{realTimeControl.fanSpeed == 0}" />		
											<h:outputText value="#{msg.fan_speed_high}" rendered="#{realTimeControl.fanSpeed == 1}" />
											<h:outputText value="#{msg.fan_speed_mid}" rendered="#{realTimeControl.fanSpeed == 2}" />
											<h:outputText value="#{msg.fan_speed_low}" rendered="#{realTimeControl.fanSpeed == 3}" />				
										</rich:column>

										<rich:column width="95px" style="text-align: center;">
											<f:facet name="header">
								                <h:outputText value="#{msg.key_lock}" />
								            </f:facet>				 
											
											<h:outputText value="#{msg.key_lock_no_lock}" rendered="#{realTimeControl.keyLock == 0}" />		
											<h:outputText value="#{msg.key_lock_fan_speed_only}" rendered="#{realTimeControl.keyLock == 1}" />																	
										</rich:column>

										<rich:column width="100px" style="text-align: center;">
											<f:facet name="header">
								                <h:outputText value="#{msg.error_message}" />
								            </f:facet>						 
											<h:outputText value="#{msg.error_message_disconnected}" rendered="#{realTimeControl.errorMessage == 3}"/>
											<h:outputText value="" rendered="#{realTimeControl.errorMessage != 3}"/>					
										</rich:column>
										
										<f:facet name="footer">
						                    <rich:dataScroller maxPages="10"/>
						                </f:facet>	

									</rich:extendedDataTable>
								</td>
							</tr>
						</table>
					</rich:panel>
					
					<rich:panel header="#{msg.real_time_command}" style="font-size: 16px;" rendered="#{sec:ifAnyGranted('ROLE_ADMIN, ROLE_SUPERVISOR')}">
						<table>
							<tr>
								<td>
									<h:outputText value="#{msg.start_option}" styleClass="outputText" style="font-size: 16px;" />
									<h:outputText value="&#160;" />	
								</td>
								<td>
									<h:selectOneMenu 
										styleClass="short_selectClass" value="#{massRealTimeManageBean.realTimeControl.start}" >									
										<f:selectItem itemLabel="#{msg.start_on}" itemValue="#{true}" />
										<f:selectItem itemLabel="#{msg.start_off}" itemValue="#{false}" />
									</h:selectOneMenu>
								</td>
								
								<td>
									<h:outputText value="&#160;" />	
									<h:outputText value="&#160;" />	
									<h:outputText value="&#160;" />	
								</td>
								
								<td>
									<h:outputText value="#{msg.fan_speed}" styleClass="outputText" style="font-size: 16px;" />
									<h:outputText value="&#160;" />	
								</td>
								
								
								<td>
									<h:selectOneMenu 
										styleClass="short_selectClass" value="#{massRealTimeManageBean.realTimeControl.fanSpeed}" >									
										<f:selectItem itemLabel="#{msg.fan_speed_auto}" itemValue="#{0}" />
										<f:selectItem itemLabel="#{msg.fan_speed_high}" itemValue="#{1}" />
										<f:selectItem itemLabel="#{msg.fan_speed_mid}" itemValue="#{2}" />
										<f:selectItem itemLabel="#{msg.fan_speed_low}" itemValue="#{3}" />
										
									</h:selectOneMenu>
								</td>
								
								<td>
								</td>
								
							</tr>
							
							<tr>
								<td>
									<h:outputText value="#{msg.temperature}(#{msg.celsius})" styleClass="outputText" style="font-size: 16px;" />
									<h:outputText value="&#160;" />	
								</td>
								<td>
									<h:selectOneMenu 
										styleClass="short_selectClass" value="#{massRealTimeManageBean.realTimeControl.temperature}" >									
										<f:selectItems value="#{massRealTimeManageBean.temperatureOptions}" />
									</h:selectOneMenu>
								</td>
								
								<td>
									<h:outputText value="&#160;" />	
									<h:outputText value="&#160;" />	
									<h:outputText value="&#160;" />	
								</td>
								
								<td>
									<h:outputText value="#{msg.key_lock}" styleClass="outputText" style="font-size: 16px;" />
									<h:outputText value="&#160;" />	
								</td>
								
								
								<td>
									<h:selectOneMenu 
										styleClass="short_selectClass" value="#{massRealTimeManageBean.realTimeControl.keyLock}" >									
										<f:selectItem itemLabel="#{msg.key_lock_no_lock}" itemValue="#{0}" />
										<f:selectItem itemLabel="#{msg.key_lock_fan_speed_only}" itemValue="#{1}" />									
									</h:selectOneMenu>
								</td>
								
								<td>							
								</td>
							</tr>
							
							<tr>
								<td>
									<h:outputText value="#{msg.minimum_temperature}(#{msg.celsius})" styleClass="outputText" style="font-size: 16px;" />
									<h:outputText value="&#160;" />	
								</td>
								<td>
									<h:selectOneMenu 
										styleClass="short_selectClass" value="#{massRealTimeManageBean.realTimeControl.minimumTemperature}" >									
										<f:selectItems value="#{massRealTimeManageBean.minimumTemperatureOptions}" />
									</h:selectOneMenu>
								</td>
								
								<td>
									<h:outputText value="&#160;" />	
									<h:outputText value="&#160;" />	
									<h:outputText value="&#160;" />	
								</td>
								
								<td>
								</td>
																								
								
								<td>
									<a4j:commandButton 
										id="send_btn"
										styleClass="buttonClass" style="font-size: 16px;" 
										value="#{msg.apply}" action="#{massRealTimeManageBean.send}" 										
										render="@form" rendered="#{massRealTimeManageBean.allowControl}" />								
								</td>
																
							</tr>
						</table>
					</rich:panel>
					
				</h:panelGrid>				

			</h:form>			        

		</ui:define>
	</ui:composition>
</body>
</html>
